package com.feng.controller;

import com.feng.entity.RestResponse;
import com.feng.entity.vo.TagAddVo;
import com.feng.entity.vo.TagPageReqVo;
import com.feng.service.TagService;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/tag")
public class TagController {

    final TagService tagService;

    public TagController(TagService tagService) {
        this.tagService = tagService;
    }

    //获取所有标签
    @PreAuthorize("@ps.hasPermission('content:article:write')")
    @GetMapping("/allList")
    public RestResponse listAllTag(){
        return tagService.listAllTag();
    }

    //分页获取所有标签
    @PreAuthorize("@ps.hasPermission('system:tag:query')")
    @PostMapping("/listAllTag")
    public RestResponse listAllPageTag(@RequestBody TagPageReqVo tagPage){
        return tagService.listAllPageTag(tagPage);
    }

    //添加标签
    @PreAuthorize("@ps.hasPermission('system:tag:add')")
    @PostMapping("/addTag")
    public RestResponse addTag(@RequestBody TagAddVo tagAdd){
        return tagService.addTag(tagAdd);
    }

    //通过id获取标签信息
    @PreAuthorize("@ps.hasPermission('system:tag:query')")
    @GetMapping("/{id}")
    public RestResponse getTagById(@PathVariable Long id){
        return tagService.getTagById(id);
    }

    @PreAuthorize("@ps.hasPermission('system:tag:edit')")
    @PutMapping("/updateTag")
    public RestResponse updateTag(@RequestBody TagAddVo tagAdd){
        return tagService.updateTag(tagAdd);
    }

    @PreAuthorize("@ps.hasPermission('system:tag:remove')")
    @DeleteMapping("/deleteTag/{id}")
    public RestResponse deleteTag(@PathVariable Long id){
        return tagService.deleteTag(id);
    }

    @PreAuthorize("@ps.hasPermission('system:tag:remove')")
    @DeleteMapping("/delBatchTag/{ids}")
    public RestResponse delBatchTag(@PathVariable List<Long> ids){
        return tagService.delBatchTag(ids);
    }

    @PreAuthorize("@ps.hasPermission('system:tag:export')")
    @GetMapping("/export")
    public void export(HttpServletResponse response){
        tagService.export(response);
    }
}
